home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with c code, please help!
- Date: 22 Jan 1996 19:22:54 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan22122254@qcd.lanl.gov>
- References: <surgsw-1901960148530001@128.206.206.86> <4e0hn0$e80@spanky.pls.ov.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: glenn@ov.com's message of 22 Jan 1996 17:32:16 GMT
-
- --text follows this line--
- In article <4e0hn0$e80@spanky.pls.ov.com> glenn@ov.com
- (Fletcher.Glenn@ov.com) writes:
- <snip>
- >#include <stdio.h>
- >
- >main()
- >{
- > int i=0;
- > char word[100], c;
- > printf("Enter a word: ");
- > while( (c = getchar()) != '\n') {
- > *word = c;
- ^^^^^
- Problem #1, word is not a pointer. You can't dereference it. If you
- wish to use a pointer into the "word" array, you need to create and
- initialize the pointer.
-
- Please read the FAQ before posting incorrect opinions. word is not a
- pointer, but it _decays_ to a pointer value (aka rvalue) except when
- used as an immediate operand of & or sizeof. In particular *word is
- exactly the same as word[0].
-
- (In a previous post, I mistakenly wrote that an array always decays to
- a pointer under these circumstances. Technically, this is not correct:
- but I admit I should have been careful. Those that did not spot my
- earlier mistake, please ignore this note as well: it is not something
- worth getting confused about.)
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-